<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<script>
    window.onload=function () {
        document.querySelector("#getTime").onclick=function () {
            var ajax=new XMLHttpRequest();
            ajax.open('get','/getTime2',true);
            ajax.onreadystatechange=function () {
                console.log(1);
                var state=ajax.readyState;
                var status=ajax.status;
                if(state==4&&status==200){
                    var date=ajax.responseText;
                    console.log(date);
                    var obj=JSON.parse(date);
                    console.log(obj);
                    document.querySelector('#time').innerHTML=obj.msg;
                }
            };
            ajax.send();
        }
    }
</script>
</head>
<body>
<span id="time" style="color:green"></span>
<button id="getTime">获取系统时间</button>
</body>
</html>